from sqlalchemy import Column, Integer, Date, Boolean, String, Text, DateTime
from sqlalchemy.sql import func
from backend.config.database import Base


class HolidayInfo(Base):
    """节假日信息表"""
    __tablename__ = "holiday_info"
    
    id = Column(Integer, primary_key=True, autoincrement=True, comment='主键')
    dt = Column(Date, unique=True, nullable=False, comment='日期')
    is_holiday = Column(Boolean, nullable=False, comment='是否节假日')
    h_name = Column(String(64), nullable=True, comment='节假日名称')
    h_type = Column(String(32), nullable=True, comment='节假日类型')
    
    class Config:
        from_attributes = True


class HolidayRules(Base):
    """节假日规则表"""
    __tablename__ = "holiday_rules"
    
    id = Column(Integer, primary_key=True, autoincrement=True, comment='主键')
    h_name = Column(String(64), nullable=False, comment='节假日名称')
    h_type = Column(String(32), nullable=False, comment='节假日类型')
    rule_type = Column(String(16), nullable=False, comment='规则类型(fixed/easter/relative)')
    month = Column(Integer, nullable=True, comment='月份(1-12)')
    day = Column(Integer, nullable=True, comment='日期(1-31)')
    week_offset = Column(Integer, default=0, comment='周偏移(用于相对日期)')
    day_of_week = Column(Integer, default=0, comment='星期几(0=周日,1=周一...)')
    description = Column(Text, nullable=True, comment='规则描述')
    is_active = Column(Boolean, default=True, comment='是否启用')
    created_at = Column(DateTime, default=func.now(), comment='创建时间')
    
    class Config:
        from_attributes = True